<template>
   <div>
       <h1>当前求和为:{{sum}}</h1>
       <h3>当前求和放大10倍为：{{bigSum}}</h3>
       <h3>我在{{school}},学习{{subject}}</h3>
       <h3 style="color:red">下方组件的总人数是：{{personList.length}}</h3>
       <select v-model.number="n">
            <option value="1">1</option>
            <option value="2">2</option>
            <option value="3">3</option>
       </select>
       <button @click="increment(n)">+</button>
       <button @click="derement(n)">-</button>
       <button @click="incrementOdd(n)">当前求和为奇数在加</button>
       <button @click="incrementWait(n)">等一等在加</button>
   </div>
</template>

<script>
//引入映射状态工具 优化代码
import {mapState,mapGetters,mapMutations, mapActions} from 'vuex'

    export default {
       name:'Count',
       data(){
            return{
                n:1, //用户选择的数值
                
            }
        },
        methods:{
            //借助mapMutations简化 需要在元素单机事件传递参数increment(n) 如果名字相同也可以使用数组写法
            ...mapMutations('countOptions',{increment:'JIA',derement:'JIAN'}),
            
            ...mapActions('countOptions',{incrementOdd:'jiaOdd',incrementWait:'jiaWait'})
        },
        computed:{
            //借助mapState生成计算属性，从state中读取数据。（数组写法）['sum']一个值代表了计算函数名和state数据名
            ...mapState('countOptions',['sum','school','subject']),
            ...mapState('personOptions',['personList']),
            
            
           //同理还有个mapGetter生成计算属性，从getters中读取数据。 (数组写法)
            ...mapGetters('countOptions',['bigSum']),
        }
    }
</script>
<style scoped>
  button{
      margin-left: 5px;
  }
</style>
